/*
 * 作者：姚俊
 * 功能：按照名称查询论文
 * 日期：2015-05-25
 */
package admin.action.fruits;

import java.io.UnsupportedEncodingException;
import java.util.List;

import admin.service.fruits.PaperService;

import com.opensymphony.xwork2.ActionContext;

import teacher.bean.Paper;

public class PaperNameAction {
	
	
	private List<Paper> papers;
	private String name;
	private int flag;
	private int code;
	//当前页
	private int currentPage;
	//最后一页
	private int endPage;
	private int counts;

	public List<Paper> getPapers() {
		return papers;
	}

	public void setPapers(List<Paper> papers) {
		this.papers = papers;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}
	
	public int getCounts() {
		return counts;
	}

	public void setCounts(int counts) {
		this.counts = counts;
	}

	public String execute()
	{
				
		if(this.getCode()==1)
		{
			try {
				this.setName(new String(this.getName().getBytes("iso-8859-1"),"utf-8"));
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
				
		int add=0;
		if((new PaperService().getCountPaperByName(this.getName())%Constant.pageSize)!=0)
		{
			add=1;
		}
		
		ActionContext.getContext().put("flag", 2);
		this.setFlag(2);
	//	ActionContext.getContext().put("name", this.getName());
		this.setEndPage(new PaperService().getCountPaperByName(this.getName())/Constant.pageSize+add);
		this.setCounts(new PaperService().getCountPaperByName(this.getName()));
		papers=new PaperService().getSegregatePaperByName(this.getName(),
				(this.getCurrentPage()-1)*Constant.pageSize+1, Constant.pageSize);
		return "succ";
	}

}
